home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / telecom / 107 / c / tinyrd.c < prev   
Encoding:
C/C++ Source or Header  |  1987-02-20  |  2.5 KB  |  146 lines

  1. /******************************/
  2. /*     Tiny format loader     */
  3. /* Copyright 1986 Tom Hudson  */
  4. /******************************/
  5.  
  6. #include <osbind.h>
  7.  
  8. /**********************/
  9. /* GLOBAL VARIABLES   */
  10. /**********************/
  11.  
  12. int contrl[12];
  13. int intin[128];
  14. int ptsin[128];
  15. int intout[128];
  16. int ptsout[128];
  17.  
  18. char bad_file[]=
  19. "[1][ |This file has an incorrect | format!| ][ Sorry ]";
  20.  
  21. int colors[16];
  22. unsigned int ctl_cnt,dat_cnt;
  23. long act_ctl,act_dat;
  24. char head1[4],*ctl_ptr,picrez;
  25. int *dat_ptr,*sc_data,sc_ix;
  26.  
  27. /* temporary work buffers */
  28.  
  29. static char ctlbuf[10680];
  30. static int datbuf[16000];
  31.  
  32. /* Set up your screen buffer (32000 bytes, aligned on 256 byte boundary) */
  33. /* Place address in 'screen'.                         */
  34.  
  35. long screen;
  36.  
  37. /***************************************************/
  38. /* Open .TNY file, then call do_tiny(file_handle); */
  39. /***************************************************/
  40.  
  41. do_tiny(fhand)
  42. int fhand;
  43. {
  44. Fread(fhand,1L,&picrez);
  45. if(picrez>2)
  46.  {
  47.  picrez-=3;
  48.  Fread(fhand,4L,head1);        /* head1 holds color cycling data */
  49.  }
  50. Fread(fhand,32L,colors);    /* palette            */
  51. Fread(fhand,2L,&ctl_cnt);    /* control size in bytes    */
  52. Fread(fhand,2L,&dat_cnt);    /* data size in words        */
  53.  
  54. if(ctl_cnt>10667 || dat_cnt>16000)
  55.  {
  56.  form_alert(1,bad_file);
  57.  }
  58. else
  59.  {
  60.  act_ctl=Fread(fhand,(long)ctl_cnt,ctlbuf);    /* Read control data    */
  61.  ctl_ptr=(char *)ctlbuf;
  62.  
  63.  dat_cnt*=2;                    /* convert to bytes    */
  64.  act_dat=Fread(fhand,(long)dat_cnt,datbuf);    /* read image data    */
  65.  dat_ptr=(int *)datbuf;
  66.  
  67.  if(act_ctl==(long)ctl_cnt && act_dat==(long)dat_cnt)
  68.   decompress();
  69.  else
  70.   form_alert(1,bad_file);
  71.  }
  72. Fclose(fhand);
  73. }
  74.  
  75. decompress()
  76. {
  77. register int ix,repct;
  78. register char ctlbyte;
  79.  
  80. sc_ix=0;
  81. sc_data=(int *)screen;
  82.  
  83. for(ix=0; ix<ctl_cnt; ++ix)
  84.  {
  85.  ctlbyte=ctl_ptr[ix];
  86.  if(ctlbyte<0)
  87.   {
  88.   unique((int)(-ctlbyte));
  89.   }
  90.  else
  91.  if(ctlbyte==0 || ctlbyte==1)
  92.   {
  93.   repct=(int)ctl_ptr[++ix];
  94.   repct=(repct<<8) | ((int)ctl_ptr[++ix] & 0x00ff);
  95.   if(ctlbyte==0)
  96.    {
  97.    repeat(repct);
  98.    }
  99.   else
  100.    {
  101.    unique(repct);
  102.    }
  103.   }
  104.  else
  105.   {
  106.   repeat((int)ctlbyte);
  107.   }
  108.  }
  109. }
  110.  
  111. unique(count)
  112. int count;
  113. {
  114. register int ix,data;
  115.  
  116. for(ix=0; ix<count; ++ix)
  117.  {
  118.  toscreen(*dat_ptr);
  119.  dat_ptr++;
  120.  }
  121. }
  122.  
  123. repeat(count)
  124. int count;
  125. {
  126. register int ix,data;
  127.  
  128. data= *dat_ptr;
  129. dat_ptr++;
  130. for(ix=0; ix<count; ++ix)
  131.  toscreen(data);
  132. }
  133.  
  134. toscreen(data)
  135. int data;
  136. {
  137. sc_data[sc_ix]=data;
  138. sc_ix+=80;
  139. if(sc_ix>15999)
  140.  {
  141.  sc_ix-=15996;
  142.  if(sc_ix>79)
  143.   sc_ix-=79;
  144.  }
  145. }
  146. əəəəəəəəəəəəəəəə